<?php
namespace Home\Controller;
use Think\Controller;
class findController extends Controller {
    public function index(){
        echo 'Hello Admin';
    }
        public function typography(){
        //调用模型层获取数据
        $lostmodel = M('lost');
        //var_dump($lostmodel);
        $lost = $lostmodel->select();
        //desc倒序 asc顺序
        
        //调用视图层显示数据
        $this->lost=$lost;
        //var_dump($lost);
        $this->display();
    }   




    public function dellost($id){


        //调用模型层获取数据
        $lostmodel = M('lost');
        $lostinfo=$lostmodel->where("id=$id")->find();
        
      if ($lostinfo["picture"]=="default.jpg") {

        }
            else{
                unlink(realpath("./Public/Uploads/lostphoto/".$lostinfo["picture"]));
            }
            
        
        if (false !== $lostmodel->where("id=$id")->delete()) {
            $this->success('接单成功！');//success显示笑脸
        } else {
            $this->error('接单失败 ');//显示一个哭脸
        }
    }

    //     public function jiedan(){
    //     $goods=D('goods');
    //     if ($goods->create()) {
    //         if ($_FILES['file']['error']==0){
    //             $logoinfo = $this->myupload();
    //             $pname = $logoinfo['file']['savename'];
    //             /*dump($logoinfo);
    //             echo "$pname";  
    //             exit;*/
    //         }
    //         else{
    //             $pname="default.jpg";
    //         }

    //         $image = new \Think\Image();
    //         $image->open('./Public/Uploads/findphoto/'.$pname);
    //         $image->thumb(150,150)->save('./Public/Uploads/findphoto/'.$pname);
    //         $goods->picture=$pname;
    //         if (false!==$goods->add()){
    //             echo $goods->getLastSql();
    //             //exit();
    //             $this->success('接单成功');
    //         }
    //         else
    //         {
    //             $this->error('接单失败');
    //         }
    //     }
    //     else{
    //         $this->error($goods->getError());
    //     }
    // }
    public function myupload(){
        $upload=new \Think\Upload();//实例化ThinkPhp自带上传类
        $upload->maxSize = 3145728;//设置上传附件大小
        $upload->exts = array('jpg','jpeg','png','gif');//设置附件上传类型
        $upload->rootPath = './Public/Uploads/findphoto/';
        //$upload->savePath='';
        $upload->autoSub =false;
        
        $upload->saveName = time().'_'.mt_rand();
        $info = $upload->upload();  // 上传文件
        
        if (!$info) {
            $this->error($upload->getError());
        }
        else{
            return $info;
        }
    }
}